package com.tywj.lib.core.common.util

import java.io.File
import java.io.IOException
import java.io.RandomAccessFile

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : 文件工具类
 *     version: 1.0.0
 * </pre>
 */
object FileUtil {

    fun fileToByte(file: File): ByteArray {
        val raf = RandomAccessFile(file, "r")
        var ba: ByteArray = byteArrayOf()
        raf.use {
            val var2: Long = it.length()
            val var1: Int = var2.toInt()

            if (var1.toLong() != var2) {
                throw IOException("File size >= 2 GB")
            }

            ba = ByteArray(var1)
            it.readFully(ba)
        }

        return ba
    }
}